package com.lmx.repoDomain.tmodel;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 设备表
 */
@JsonApiResource(type = "device")
@Table(name = "tnb_device")
@Entity
public class Device extends BaseEntity {
	private String remark;// 备注

	private User lastUpdateUser;// 更新操作者userid

	private Integer createDateTime;// 创建时间

	private User createUser;

	private Integer lastUpdateDateTime;// 更新时间

	private DeviceType type;// 包含类别 厂商 等等

	private String seq;

	private Dicttype status;// 空闲 使用中 未复位

	private Short deviceStatus;// 0:异常 1： 正常 设备状态

	private Dicttype deviceType;// 具体硬件类别

	private Integer statusDate;// 最近状态时间

	private Dicttype bindStatus;// 已绑定，空闲

	private String operateTarget;

	private String operateFlag;// 解绑 绑定操作

	// 摄像头相应字段
	private String domainName;// 域名

	private String appName;// 应用名

	private String streamName;// 直播流名

	private String liveUrl;// 推流地址

	private String viewUrl;// 直播地址

	@Column(name = "domain_name")
	public String getDomainName() {
		return domainName;
	}

	public void setDomainName(String domainName) {
		this.domainName = domainName;
	}

	@Column(name = "app_name")
	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	@Column(name = "stream_name")
	public String getStreamName() {
		return streamName;
	}

	public void setStreamName(String streamName) {
		this.streamName = streamName;
	}

	@Column(name = "live_url")
	public String getLiveUrl() {
		return liveUrl;
	}

	public void setLiveUrl(String liveUrl) {
		this.liveUrl = liveUrl;
	}

	@Column(name = "view_url")
	public String getViewUrl() {
		return viewUrl;
	}

	public void setViewUrl(String viewUrl) {
		this.viewUrl = viewUrl;
	}

	@Transient
	public String getOperateTarget() {
		return operateTarget;
	}

	public void setOperateTarget(String operateTarget) {
		this.operateTarget = operateTarget;
	}

	@Transient
	public String getOperateFlag() {
		return operateFlag;
	}

	public void setOperateFlag(String operateFlag) {
		this.operateFlag = operateFlag;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "bind_status_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getBindStatus() {
		return bindStatus;
	}

	public void setBindStatus(Dicttype bindStatus) {
		this.bindStatus = bindStatus;
	}

	@Column(name = "status_date")
	public Integer getStatusDate() {
		return statusDate;
	}

	public void setStatusDate(Integer statusDate) {
		this.statusDate = statusDate;
	}

	@Column(name = "device_status")
	public Short getDeviceStatus() {
		return deviceStatus;
	}

	public void setDeviceStatus(Short deviceStatus) {
		if (deviceStatus == null) {
			deviceStatus = 1;
		}
		this.deviceStatus = deviceStatus;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "devicetype_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getDeviceType() {
		return deviceType;
	}

	public void setDeviceType(Dicttype deviceType) {
		this.deviceType = deviceType;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "type_id", foreignKey = @ForeignKey(name = "null"))
	public DeviceType getType() {
		return type;
	}

	public void setType(DeviceType type) {
		this.type = type;
	}

	@Column(name = "seq")
	public String getSeq() {
		return seq;
	}

	public void setSeq(String seq) {
		this.seq = seq;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "status_id", foreignKey = @ForeignKey(name = "null"))
	public Dicttype getStatus() {
		return status;
	}

	public void setStatus(Dicttype status) {
		this.status = status;
	}

	public Device() {

	}

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "createuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@JsonApiToOne
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "lastupdateuser_id", foreignKey = @ForeignKey(name = "null"))
	public User getLastUpdateUser() {
		return lastUpdateUser;
	}

	public void setLastUpdateUser(User lastUpdateUser) {
		this.lastUpdateUser = lastUpdateUser;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
